package com.yaowk.sfp.system.server.entity;

import com.yaowk.sfp.common.db.BaseEntity;
import com.yaowk.sfp.common.db.GeneratorNote;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Getter
@Setter
@ToString
@Entity
@DynamicInsert
@DynamicUpdate
public class SysUser extends BaseEntity<Long> {

    @GeneratorNote("用户名")
    @Column(unique = true, nullable = false)
    private String username;
    @GeneratorNote("密码")
    @Column(nullable = false)
    private String password;
    @GeneratorNote("昵称")
    private String nickName;
    @GeneratorNote("头像")
    private String headUrl;
    @GeneratorNote("创建时间")
    @Column(nullable = false, updatable = false)
    @CreationTimestamp
    private Date createTime;
    @GeneratorNote("状态")
    @ColumnDefault("1")
    private Byte status;

    @ManyToMany
    @JoinTable(name = "sys_user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<SysRole> roles;
    @Version
    private Integer version;
}
